package com.cmict.data.bpm.api.instance;

import com.cmict.data.bpm.api.instance.dto.BpmProcessInstanceCreateReqDTO;
import com.cmict.data.bpm.api.instance.dto.BpmProcessInstancePageItemRespDTO;
import com.cmict.data.bpm.api.instance.dto.BpmProcessInstancePageReqDTO;
import com.cmict.data.bpm.api.instance.dto.BpmProcessInstanceStatusDTO;
import com.cmict.data.bpm.enums.ApiConstants;
import com.cmict.data.framework.common.pojo.CommonResult;
import com.cmict.data.framework.common.pojo.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import javax.validation.Valid;

/**
 * 流程实例 Api 接口
 *
 * @author awesome
 */
@FeignClient(name = ApiConstants.NAME)
@Api(tags = "RPC 服务 - 流程")
public interface BpmProcessInstanceApi {

    String PREFIX = ApiConstants.PREFIX + "/instance";

    /**
     * 创建流程实例（提供给内部）
     *
     * @param userId 用户编号
     * @param reqDTO 创建信息
     * @return 实例的编号
     */
    @PostMapping(PREFIX + "/create")
    @ApiOperation("创建流程实例")
    String createProcessInstance(@RequestParam("userId") Long userId, @Valid @RequestBody BpmProcessInstanceCreateReqDTO reqDTO);

    /**
     * 1. 我的流程
     **/

    @GetMapping(PREFIX + "/get")
    @ApiOperation("获取我发起的流程")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "1", example = "1024", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(name = "processDefinitionId", value = "1", example = "1024", required = true, dataTypeClass = String.class),
    })
    CommonResult<PageResult<BpmProcessInstancePageItemRespDTO>> getInstance(@RequestParam("userId") Long userId,
                                                                            @Valid BpmProcessInstancePageReqDTO pageReqDTO);
    /**
     * 查询流程状态
     **/

    @GetMapping(PREFIX + "/instance-status")
    @ApiOperation("获取流程状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "formId", value = "1", example = "1024", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(name = "recordId", value = "1", example = "1024", required = true, dataTypeClass = String.class),
    })
    CommonResult<BpmProcessInstanceStatusDTO> getInstanceStatus(@RequestParam("formId") String formId, @RequestParam("recordId") String recordId);

    /**
     * 查询流程状态
     **/

    @GetMapping(PREFIX + "/bind-process")
    @ApiOperation("查看表单是否绑定了流程")
    @ApiImplicitParam(name = "formId", value = "1", example = "1024", required = true, dataTypeClass = Long.class)
    Boolean bindProcess(@RequestParam("formId") Long formId);


    @GetMapping(PREFIX + "/update-process")
    @ApiOperation("目录迁移后更新流程")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "bpmInstanceId", value = "1", example = "1024", required = true, dataTypeClass = String.class),
        @ApiImplicitParam(name = "newMenuId", value = "1", example = "1", dataTypeClass = Long.class),
        @ApiImplicitParam(name = "newDeptId", value = "1", example = "1", dataTypeClass = Long.class),
    })
    CommonResult<Boolean> updateFormVariable(@RequestParam("bpmInstanceId") String bpmInstanceId,
                               @RequestParam("newMenuId") Long newMenuId,
                               @RequestParam("newDeptId") Long newDeptId);

}
